/**
 * 禁止多开
 */
const { app, BrowserWindow } = require('electron')

module.exports = () => {
  let gotTheLock = app.requestSingleInstanceLock()
  if (!gotTheLock) {
    app.exit()
  } else {
    app.on('second-instance', () => {
      let myWindows = BrowserWindow.getAllWindows()
      myWindows.forEach(win => {
        if (win && !win.isDestroyed()) {
          if (win.isMinimized()) win.restore()
          win.focus()
        }
      })
    })
  }
}
